﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OUSMS.AppLogic.DataAccessLayer;
using OUSMS.AppLogic.BusinessLogicLayer;
namespace OUSMS
{
    public partial class MyMotionList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MotionsBLL motionsBLL = new MotionsBLL();
                myMotionsGridView.DataSource = motionsBLL.GetMotionsByProserID(User.Identity.Name).ToList();
                myMotionsGridView.DataBind();
            }
        }


        protected void myMotionsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label indexLbl = e.Row.FindControl("indexLbl") as Label;
                indexLbl.Text = (e.Row.RowIndex + 1).ToString();

                Motions motionEntity = e.Row.DataItem as Motions;
                if (motionEntity.Status != "待提交")
                {
                    HyperLink modifyHyperLink = e.Row.FindControl("modifyHyperLink") as HyperLink;
                    modifyHyperLink.Enabled = false;

                    LinkButton deleteLinkButton = e.Row.FindControl("deleteLinkButton") as LinkButton;
                    deleteLinkButton.Enabled = false;
                    deleteLinkButton.OnClientClick = "";
                }
            }
        }

        protected void deleteLinkButton_Click(object sender, EventArgs e)
        {
            LinkButton deleteLinkButton = sender as LinkButton;
            MotionsBLL motionsBLL = new MotionsBLL();
            Motions motionEntity = motionsBLL.GetMotionsByID(Convert.ToInt64(deleteLinkButton.CommandArgument));
            motionEntity.IsDeleted = true;
            motionsBLL.Save();

            myMotionsGridView.DataSource = motionsBLL.GetMotionsByProserID(User.Identity.Name).ToList();
            myMotionsGridView.DataBind();
        }
    }
}